<template>
  <div>

    <div>
      <a-descriptions title="账户信息" bordered>
        <a-descriptions-item label="用户名">{{ userUn.name }}</a-descriptions-item>
        <a-descriptions-item label="账号">{{ userUn.account }}</a-descriptions-item>
        <a-descriptions-item label="密码">
          <div style="display: flex; align-items: center;">
            <a-button size="small" @click="visible = !visible">修改密码</a-button>
          </div>
        </a-descriptions-item>
        <a-descriptions-item label="平台"><span style="color: red;">抖音</span></a-descriptions-item>
        <a-descriptions-item label="小程序"><span style="color: red;">宏琦舍</span></a-descriptions-item>
        <a-descriptions-item></a-descriptions-item>
        <a-descriptions-item label="模式">广告</a-descriptions-item>
        <a-descriptions-item></a-descriptions-item>
        <a-descriptions-item></a-descriptions-item>
        <!-- 宏琦舍 -->
        <a-descriptions-item label="累计收益">￥{{ userUn.adPriceAll }}</a-descriptions-item>
        <a-descriptions-item label="已提现收益">￥{{ userUn.alreadyproposePrice }}</a-descriptions-item>
        <a-descriptions-item label="广告星图任务收益预扣（20%）">￥{{ userUn.freezePriceAll }}</a-descriptions-item>
        <a-descriptions-item label="星图累计结算收益">投稿后67天以星图数据为准</a-descriptions-item>
        <a-descriptions-item label="可提现收益">
          <div style="display: flex;  align-items: center;">
            <!-- <span style="margin-right: 20px;">￥{{ userUn.proposePrice }}</span> -->
            <span style="margin-right: 20px;">￥{{ (userUn.adPriceAll - userUn.alreadyproposePrice - userUn.freezePriceAll).toFixed(2) }}</span>
          </div>
        </a-descriptions-item>
        <a-descriptions-item></a-descriptions-item>
        <a-descriptions-item label="模式">付费</a-descriptions-item>
        <a-descriptions-item></a-descriptions-item>
        <a-descriptions-item></a-descriptions-item>
        <a-descriptions-item label="累计收益">
          <div style="display: flex;  align-items: center;">
            <span style="margin-right: 20px;">￥{{ (userUn.totalDyPriceAll * 0.001).toFixed(2) }}</span>
            <!-- <a-button size="small">发起提现</a-button> -->
          </div>
        </a-descriptions-item>
        <a-descriptions-item label="已提现收益">￥{{ (userUn.dyAlreadyProposePrice * 0.001).toFixed(2) }}</a-descriptions-item>
        <a-descriptions-item label="可提现收益">￥{{ ((userUn.totalDyPriceAll * 0.001) - userUn.dyAlreadyProposePrice* 0.001).toFixed(2) }}</a-descriptions-item>
        <a-descriptions-item label="平台"><span style="color: red;">快手</span></a-descriptions-item>
        <a-descriptions-item label="小程序"><span style="color: red;">一品布衣</span></a-descriptions-item>
        <a-descriptions-item></a-descriptions-item>
        <a-descriptions-item label="模式">付费</a-descriptions-item>
        <a-descriptions-item></a-descriptions-item>
        <a-descriptions-item></a-descriptions-item>
        <a-descriptions-item label="累计收益">
          <div style="display: flex;  align-items: center;">
            <span style="margin-right: 20px;">￥{{ (userUn.totalKsPriceAll * 0.001).toFixed(2) }}</span>
            <!-- <a-button size="small">发起提现</a-button> -->
          </div>
        </a-descriptions-item>
        <a-descriptions-item label="已提现收益">￥{{ (userUn.ksAlreadyProposePrice * 0.001).toFixed(2)}}</a-descriptions-item>
        <a-descriptions-item label="可提现收益">￥{{ ((userUn.totalKsPriceAll- userUn.ksAlreadyProposePrice) * 0.001).toFixed(2) }}</a-descriptions-item>

        <a-descriptions-item label="平台"><span style="color: red;">快手</span></a-descriptions-item>
        <a-descriptions-item label="小程序"><span style="color: red;">深海漫故事</span></a-descriptions-item>
        <a-descriptions-item></a-descriptions-item>
        <a-descriptions-item label="模式">付费</a-descriptions-item>
        <a-descriptions-item></a-descriptions-item>
        <a-descriptions-item></a-descriptions-item>
        <a-descriptions-item label="累计收益">
          <div style="display: flex;  align-items: center;">
            <span style="margin-right: 20px;">￥{{ (userUn.totalKsPriceAllQd * 0.001).toFixed(2) }}</span>
          </div>
        </a-descriptions-item>
        <a-descriptions-item label="已提现收益">￥{{ (userUn.ksAlreadyProposePriceQd * 0.001).toFixed(2)}}</a-descriptions-item>
        <a-descriptions-item label="可提现收益">￥{{ ((userUn.totalKsPriceAllQd- userUn.ksAlreadyProposePriceQd) * 0.001).toFixed(2) }}</a-descriptions-item>

        <a-descriptions-item label="平台"><span style="color: red;">抖音</span></a-descriptions-item>
        <a-descriptions-item label="小程序"><span style="color: red;">深海漫故事</span></a-descriptions-item>
        <a-descriptions-item></a-descriptions-item>
        <a-descriptions-item label="模式">付费</a-descriptions-item>
        <a-descriptions-item></a-descriptions-item>
        <a-descriptions-item></a-descriptions-item>
        <a-descriptions-item label="累计收益">
          <div style="display: flex;  align-items: center;">
            <span style="margin-right: 20px;">￥{{ (userUn.totalDyPriceAllQd * 0.001).toFixed(2) }}</span>
          </div>
        </a-descriptions-item>
        <a-descriptions-item label="已提现收益">￥{{ (userUn.dyAlreadyProposePriceQd * 0.001).toFixed(2)}}</a-descriptions-item>
        <a-descriptions-item label="可提现收益">￥{{ ((userUn.totalDyPriceAllQd- userUn.dyAlreadyProposePriceQd) * 0.001).toFixed(2) }}</a-descriptions-item>

        <a-descriptions-item label="操作">
          <div style="display: flex;  align-items: center;">
            <a-button @click="putInPriceAdDy" size="small">发起提现</a-button>
          </div>
        </a-descriptions-item>
      </a-descriptions>

      <div class="u_content_input">
        <div class="ant-descriptions-title" style="margin-top: 20px;">广告收益记录（抖音-宏琦舍）</div>
        <a-table :columns="columns"  :pagination="false" :data-source="data">

      
        </a-table>
      </div>
      <div style="display: flex;justify-content: end;"> <a-pagination @change="changePage" v-model:current="current"
        :total="total" show-less-items /></div>
      <loading v-if="load == 0" class="loading"></loading>
    </div>



    <a-modal v-model:visible="visible" title="修改密码" @ok="handleOk">
      <a-input-password v-model:value="password" placeholder="输入新密码" />

      <div style="margin-top: 10px;">
        <a-input-password v-model:value="passwordRepeat" placeholder="重复新密码" />
      </div>

      <div v-if="showWor" style="color: red; font-size: 13px; margin: 5px;">
        两次输入的密码不一致，请仔细检查
      </div>

    </a-modal>
  </div>
</template>

<script>
import loading from "../../components/loading.vue"
import { modifyPassword, putInPriceAdDy, getStarPriceListNew, login } from "../../http/api"

const columns = [
  {
    title: '日期',
    dataIndex: 'time',

  },
  // {
  //   title: '星图收益',

  //   dataIndex: 'starPrice',
  // },
  {
    title: '广告收益',
    dataIndex: 'todayPrice',
  },
  // {
  //   title: '抖音付费收益',
  //   dataIndex: 'todayPrice',
  // },
  // {
  //   title: '快手付费收益',
  //   dataIndex: 'todayPrice',
  // },
]

const ipagination = {
  current: 1,
  pageSize: 10,
  pageSizeOptions: ["10"],
  showTotal: (total, range) => {
    return range[0] + "-" + range[1] + " " + "共" + total + "条"
  },
  showQuickJumper: true,
  showSizeChanger: true,
  total: 0,
}

export default {
  name: "index",
  data () {
    return {
      ipagination: {},
      visible: false,
      password: '',
      passwordRepeat: '',
      showWor: false,
      userUn: {},
      columns: [],
      data: [
       
      ],
      skip: 0,
      load: 1, //加载中
      total: 0,
      current: 1,
    }
  },

  async created () {
    this.ipagination.current = 1
    this.userUn = JSON.parse(localStorage.getItem("userInfo"))
    this.getList()
    this.login()
  },

  methods: {
    async getList () {
      this.columns = columns
      this.load = 0
      const parameter = {
        "$url": "getStarPriceListNew",
        "skip": this.skip,
        "account": this.userUn.account,
      }
      const res = await getStarPriceListNew(parameter)
      var d = res.res
      this.load = 1
      this.total = res.total_count.total
      let arr = []
      d.data.forEach((item, index) => {
        arr.push({
          key: index,
          time: item.time,
          starPrice: item.starPrice,
          todayPrice: item.todayPrice,
        })
      })
      this.data = arr
      // this.data = res.res.data
      console.log(res)
    },

    async handleOk () {
      console.log(this.password)
      console.log(this.passwordRepeat)
      if (this.password != this.passwordRepeat) {
        //两次输入密码不一致
        this.showWor = true
      } else {
        this.visible = false
        //修改密码
        const parameter = {
          "$url": "modifyPassword",
          "account": this.userUn.account,
          "password": this.password,

        }
        const res = await modifyPassword(parameter)

        console.log(res)

      }

    },


    async login () {
      const parameter = {
        "$url": "adminLogin",
        "account": this.userUn.account,
        "password": this.userUn.password,
      }
      const res = await login(parameter)
      console.log(res)
      if (res.code == 200) {

        //将用户信息记录在本地缓存中
        localStorage.setItem('userInfo', JSON.stringify(res.userInfo.data[0]))

      }
    },

    //发起广告收益提现
    async putInPriceAdDy () {

      //新增提现记录
      const parameter = {
        "$url": "putInPriceAdDy",
        "userInfo": this.userUn
      }
      const res = await putInPriceAdDy(parameter)
      if (res.code === 400){
        this.$tishi("warning", res.msg)
      } else{
        this.$tishi("success", res.msg)
      }
      
    },
    changePage (e) {
      console.log(e)
      this.skip = (e - 1) * 10
      this.getList()
    },

  },
  components: {
    // edit,
    loading,
  },
}
</script>

<style>
th.column-money,
td.column-money {
  text-align: right !important;
}
</style>